package com.zl.codereview.git.swing;

import com.intellij.openapi.ui.SimpleToolWindowPanel;
import com.intellij.ui.components.JBPanel;

import java.awt.*;


public class ReviewTreePanel extends SimpleToolWindowPanel {

    protected boolean paintFlag = false;
    private String waitV = "";

    public ReviewTreePanel(){
        super(true,true);
    }

    public void startWait(){
        this.paintFlag = true;
        while(paintFlag){
            if("等待中".equals(waitV)){
                waitV = "";
            }else if("".equals(waitV)){
                waitV = "等";
            }else if("等".equals(waitV)){
                waitV = "等待";
            }else if("等待".equals(waitV)){
                waitV = "等待中";
            }
            try {
                Thread.sleep(600);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            this.repaint();
        }
    }

    public void stopWait(){
        this.paintFlag = false;
        this.waitV = "";
        repaint();
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        if(this.waitV != null && !"".equals(this.waitV)){
            g.setFont(new Font(null,Font.BOLD,17));
            int x = (this.getWidth()/2)-10;
            int y = (this.getHeight()/2)-50;
            g.drawString(this.waitV,x,y);
        }
    }

    public boolean isPaintFlag() {
        return paintFlag;
    }

    public void setPaintFlag(boolean paintFlag) {
        this.paintFlag = paintFlag;
    }
}
